import axios from 'axios';
import global from '@/components/common/httpurl.vue'

const service = axios.create({
    baseURL: 'http://192.168.1.103:8099/franchise-business-api.jfzh.com.cn', //服务器
    timeout: 200000
});
service.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
service.interceptors.request.use(
    config => {
        if (window.location.host.indexOf('192.168') > -1 || window.location.host.indexOf('localhost') > -1) {
            //判断是内网地址的话，就请求内网后端接口地址
            config.baseURL = 'http://192.168.1.103:8099/franchise-business-api.jfzh.com.cn';
            // config.baseURL = '/other';
        } else {
            //判断是外网地址的话，就请求外网后端接口地址
            config.baseURL = 'http://125.39.179.246:8099/franchise-business-api.jfzh.com.cn';
            // config.baseURL = '/other';
        }
        return config
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

service.interceptors.response.use(
    response => {
        return response.data;
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);
export default service;
